﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using compshop.web.CompShopDataService;
using System.Drawing;

namespace compshop.web
{
    public partial class ParametersForm : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            int? id = Session["idParam"] as int?;
            if (id != null && id > 0)
            {
                GeneralProduct gp = ObjectDataSource.GetGeneralProductById((int)id);
                if (gp != null && gp.Producer != null)
                {
                    lblNameProduct.Text = string.Format("{0} {1}", gp.Producer.Name, gp.Name);
                }

                List<GeneralProductParameter> parameters = ObjectDataSource.GetParameters((int)id);
                if (parameters != null)
                {
                    Label lblParam;
                    int counter = 0;
                    foreach (GeneralProductParameter param in parameters)
                    {
                        lblParam = new Label();
                        lblParam.Width = 360;
                        lblParam.Height = 20;
                        lblParam.Text = string.Format(" {0} : {1} {2}", param.Parameter.Name, param.Value.ToString(), param.Parameter.Unit);
                        lblParam.BackColor = counter % 2 != 0 ? Color.FromArgb(250, 250, 250) : Color.FromArgb(245, 245, 245);
                        divParam.Controls.Add(lblParam);
                        counter++;
                    }
                }
                photo.ImageUrl = "~/ImageHandler.ashx?id=" + id.ToString();
            }

        }   //protected void Page_Load

        protected void btnReturn_Click(object sender, EventArgs e)
        {
            Response.Redirect("Default.aspx");
        }

    }
}